package com.jidolstar.astro.datetimes
{
	import com.jidolstar.astro.utils.AstroMath;
		
	/**
	 * 그리니치 항성시(Greenwich Sidereal Time)
	 */ 
	public class GMST extends AstroDateTime
	{
		public function GMST( value:* )
		{
			if( value is Number )
			{
				super( value, JulianDateFormat.JD );
			}
			else if( value is UT )
			{
				setUT( value );
			}
			else if( value is LCT )
			{
				setLCT( value );
			}
			else if( value is LMST )
			{
				setLMST( value );
			}
			else if( value is AstroDateTime )
			{
				this.setDateTime( (value as AstroDateTime).date, (value as AstroDateTime).time );
			}			
			else
			{
				throw new ArgumentError("First parameter is wrong value type.");
			}
		}
		
		/**
		 * UT(Universal Time)으로 설정
		 * UT를 GMST로 바꾸는 부분이다.  
		 * @see 
		 *  Practical Astronomy with your calculator. P.17
		 *  http://astronote.org/board/?table_name=prog&job=view&idx=23979
		 *  http://astronote.org/board/?table_name=prog&job=view&idx=23980 
		 *  http://astronote.org/board/?table_name=prog&job=view&idx=23981
		 */ 
		public function setUT( ut:UT ):void
		{
			var ut_jd0:Number = ut.jd0;
			var ut_hours:Number = ut.hours;
			var t:Number = ( ut_jd0 - 2451545.0 ) / 36525.0;
			var t0:Number = 6.697374558 + ( 2400.051336 * t ) + ( 0.000025862 * t * t );
			t0 = AstroMath.normalize(t0, 0, 24);
			var gmst_hours:Number = ut_hours * 1.00273790935 + t0;
			gmst_hours = AstroMath.normalize( gmst_hours, 0, 24 );
			this.julianDate = new JulianDate( ut_jd0 + gmst_hours / 24.0, JulianDateFormat.JD );
			
			/*
			var ut_jd0:Number = ut.jd0;
			var ut_hours:Number = ut.hours;
		
			var d:Number = ut.jd - 2451545.0;
			var t:Number = (ut_jd0 - 2451545.0) / 36525.0;
		
			var gmst:Number = 6.697374558 + (2400.051336 * t) + (0.000025862 * t * t) + ut_hours * 1.00273790935;
			gmst = AstroMath.normalize(gmst, 0, 24);
		
			// Solve for Apparent Sidereal time by solving for the nutation in right ascension
			var om:Number = 125.04 - 0.052954 * d; //longitude of the ascending node of the moon
			var l:Number = 280.47 + 0.98565 * d; //mean longitude of the sun
			var eps:Number = 23.4393 - 0.0000004*d; //obliquity
			var delta_psi:Number = -0.000319 * Math.sin(om) - 0.000024 * Math.sin(2*l); //nutation in longitude
			var eqeq:Number = delta_psi * Math.cos(eps); //equation of the equinoxes
			var gast:Number = gmst + eqeq; //greenwich apparent sidereal time
			gast = AstroMath.normalize(gast, 0, 24);
			this.julianDate = new JulianDate( gast, JulianDateFormat.JD ); 			
			*/
			 
		}
		
		/**
		 * LMST(Local Mean Sidereal Time)로 설정 
		 */ 
		public function setLMST( lmst:LMST ):void
		{
			
		}
		
		/**
		 * LCT(Local Civil Time)로 설정 
		 */ 
		public function setLCT( lct:LCT ):void
		{
			
		}		
		
	}
}